window.EventEmitter = function() {
    this.ev = {};
}
EventEmitter.prototype.subscribe = function(key, func) {
    this.ev[key] = func();
}
EventEmitter.prototype.dispatch = function(key, data) {//key可以为数组
    if(typeof key == "string") {
        if (this.ev[key]) {
            this.ev[key].receiveMsg(data);
        }
    } else {
        for(var index = 0; index < key.length; index++) {
            this.ev[key[index]].receiveMsg(data);
        }
    }
}
EventEmitter.prototype.broadcast = function(data) {
    for(key in this.ev) {
        this.ev[key].receiveMsg(data);
    }
}
EventEmitter.prototype.call = function(key, funName) {
    arguments = [].slice.call(arguments,0);
    arguments.splice(0, 2);
    if(this.ev[key] && this.ev[key][funName]) {
        this.ev[key][funName].apply(this.ev[key], arguments);
    }
}

